<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="任务编号" prop="code">
          <el-input v-model="queryParam.qry_code" placeholder="请输入任务编号"></el-input>
        </el-form-item>
        <el-form-item label="任务名称">
          <el-input v-model="queryParam.qry_name" placeholder="请输入任务名称"></el-input>
        </el-form-item>
        <el-form-item label="所属项目编码">
          <el-input v-model="queryParam.qry_projectuucode" placeholder="请输入项目编码"></el-input>
        </el-form-item>
      </template>
    </tl-list-search>
    <!--    &lt;!&ndash; 工具栏 &ndash;&gt;-->
    <!--    <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0" :isDisplayExport="false" :isDisplayDeleteBatch="false" :isDisplayAdd="false">-->
    <!--      <template slot="left-btn"> </template>-->
    <!--    </tl-list-toolbar>-->
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
          >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="code" label="任务编号" width="150px" sortable="custom" sort-by="code" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectuucode" label="所属项目编码" width="150px" sortable="custom" sort-by="code" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="name" label="任务名称" width="150px" sortable="custom" sort-by="name" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="introduction" label="任务描述" width="150px" sortable="custom" sort-by="introduction" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispstatus" label="任务状态" width="150px" sortable="custom" sort-by="status" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="disptype" label="任务类型" width="150px" sortable="custom" sort-by="status" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planbegintime" label="计划开始时间" width="170px" sortable="custom" sort-by="planbegintime" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planendtime" label="计划结束时间" width="170px" sortable="custom" sort-by="planendtime" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="realbegintime" label="实际开始时间" width="170px" sortable="custom" sort-by="realbegintime" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="realendtime" label="实际结束时间" width="170px" sortable="custom" sort-by="realendtime" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="responsibleusercode" label="负责人工号" width="150px" sortable="custom" sort-by="responsibleusercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="responsibleusername" label="负责人名称" width="150px" sortable="custom" sort-by="responsibleusername" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="progress" label="最新任务进度百分比(%)" width="150px" sortable="custom" sort-by="progress" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <!-- <el-button type="text" icon="el-icon-edit" @click="openEditDialog('editForm', scope.row.id)">编辑</el-button>
          <el-button type="text" icon="el-icon-delete" @click="doDelete(scope.row.id)">删除</el-button> -->
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-document" @click.native="openViewDialog('editForm', scope.row.id)">查看任务</el-dropdown-item>
              <el-dropdown-item icon="el-icon-position" @click.native="startTask(scope.row.id)" v-if="scope.row.status === 0 || scope.row.status === 1">开始任务</el-dropdown-item>
              <el-dropdown-item icon="el-icon-refresh" @click.native="openProgressEdit(scope.row)" :disabled="scope.row.status !== 2" >进度反馈</el-dropdown-item>
              <el-dropdown-item icon="el-icon-view" @click.native="openHistory(scope.row)" :disabled="scope.row.status === 0 || scope.row.status === 1">反馈历史</el-dropdown-item>
              <el-dropdown-item icon="el-icon-rank" @click.native="completeTask(scope.row)" :disabled="scope.row.status === 0 || scope.row.status === 1" v-if="[0, 1, 2].includes(scope.row.status)">任务关闭</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <!--      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>-->
      <edit ref="progressEdit" @refresh="doRefresh"></edit>
      <history ref="history" :code="this.code" :round="this.round"></history>
      <task ref="editForm" @refresh="doRefresh"></task>
      <task-execute ref="taskExecuteRef" @refresh="doRefresh" :taskInfo="chooseTaskInfo"></task-execute>
    </div>
  </div>
</template>

<script>
  /** mixins */
  import { mixin_list } from '@tapui/mixins/mixin_list'
  // /** 子组件 */
  // import tlEdit from './labourEdit'
  import edit from './edit'
  import history from './indexForHistory'
  import task from './editForTaskView'
  import taskExecute from '../cbbPmTask/taskExecute'
  /** 工具类 */
  import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
  export default {
    name: 'cbbPmTask',
    mixins: [mixin_list],
    components: { edit, history, task, taskExecute },
    data() {
      return {
        description: 'WBS任务表-列表查询',
        urlPrefix: '/cbb/pmTask/',
        url: {
          queryCodeList: '/cbb/pmTask/dataCodeList',
          startTask: '/cbb/pmTask/startTask'
        },
        // 排序参数
        sorterInfo: {
          sidx: 'sortcode',
          sord: 'asc'
        },
        code: '',
        rowDbClickActionType: 'view',
        chooseTaskInfo: {},
        round: ''
      }
    },
    methods: {
      completeTask(taskInfo) {
        if (!taskInfo.nodeinsid) {
          this.$tap.alert('未到达当前任务的审批节点，暂时无法进行关闭')
          return
        }
        this.chooseTaskInfo = taskInfo
        this.$refs.taskExecuteRef.visible = true
      },
      // 打开反馈页面
      openProgressEdit(row) {
        // 项目编码
        this.$refs.progressEdit.projectuucode = row.projectuucode
        // wbs编码
        this.$refs.progressEdit.wbscode = row.wbscode
        // 任务code
        this.$refs.progressEdit.taskcode = row.code
        // 轮次
        this.$refs.progressEdit.round = row.round
        this.$refs.progressEdit.isAdd = true
        this.$refs.progressEdit.visible = true
        this.$refs.progressEdit.disableEditSubmit = false
      },
      doRowDbClick(row, column, event) {
        this.chooseTaskInfo = row
        this.$refs.taskExecuteRef.taskDetailMode = true
        this.$refs.taskExecuteRef.fromTaskExecute = true
        this.$refs.taskExecuteRef.visible = true
      },
      beforeLoadData() {
        // 查询当前自己的任务
        this.queryParam.qry_responsibleusercode = this.$store.getters.user.code
        return true
      },
      // 打开历史反馈
      openHistory(row) {
        this.code = row.code
        this.round = row.round
        this.$refs.history.visible = true
      },
      // 开始任务
      startTask(id) {
        postAction(this.url.startTask, { taskid: id }).then(res => {
          if (res.success) {
            this.doRefresh()
            this.$tap.message('任务启动成功！', 'success')
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
      }
    }
  }
</script>

<style scoped></style>

